import mysql.connector


def get_mysql_connection():
    try:
        conn = mysql.connector.connect(
            host="sh-cdb-5cce1w3k.sql.tencentcdb.com",
            port=23403,
            user="public",
            password="Aa19891216",
            database="bank_msg_push",
            charset="utf8mb4",
            use_unicode=True,
            autocommit=True,
        )
        print("数据库连接成功")
        return conn
    except Exception as e:
        print(f"数据库连接失败: {str(e)}")
        return None


if __name__ == "__main__":
    conn = get_mysql_connection()
    cursor = conn.cursor()
    cursor.execute("SET NAMES utf8mb4")
    cursor.execute("SET CHARACTER SET utf8mb4")
    cursor.execute("SET character_set_connection=utf8mb4")
    cursor.execute("SELECT * FROM customer_inquiries ORDER BY created DESC LIMIT 10")
    rows = cursor.fetchall()
    for row in rows:
        print(row)
    cursor.close()
    conn.close()
